package com.jacken.mars.commons.mq.base.producer;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * @author wangqiang
 * @version 1.0
 * @date 2021/1/2 17:58
 * 发送同步消息
 */
public class SyncProducer {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("group-01");
        producer.setNamesrvAddr("114.55.146.111:9876");
        producer.setVipChannelEnabled(false);
        producer.start();

        for (int i = 0; i < 10; i++) {
            Message message = new Message("Sync-Producer-Topic", "Tag-01", "hello world".getBytes());
            SendResult result = producer.send(message, 100000);
            SendStatus sendStatus = result.getSendStatus();
            String msgId = result.getMsgId();
            MessageQueue messageQueue = result.getMessageQueue();
            System.out.println(result);
            System.out.println("发送状态:" + sendStatus + "消息ID" + msgId + "消息队列" + messageQueue);
            Thread.sleep(1000);

        }


        producer.shutdown();

    }
}
